--[[

Copyright (c) 2012-2013 baby-bus.com

http://www.babybus.com/superdo/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

]]

----------------------
-- 模块
----------------------
-- 示例：xxx.xxx.init
local CURRENT_MODULE_NAME   = ...
-- 模块名称(去掉.init[长度为5]的字符串，推断出前面的包名为字符串的第1个字符到倒数第6个字符)
local p           			= string.sub(CURRENT_MODULE_NAME, 1, -6)







----------------------
-- 全局变量
----------------------
-- 全局数据[盒子]
box 				= {}

box.WEB_URL 		= "https://www.babybus.com/box/index.shtml"



box.WEB_NOTIFY 		= "APP_CLOSE_WEBBOX"








----------------------
-- 载入文件
----------------------
require(p .. ".g.da")
require(p .. ".g.audio")







----------------------
-- 载入类
----------------------
bb.FBoxScene 		 	= require(p .. ".g.scene.FBoxScene")







----------------------
-- 规则扩展
----------------------
-- 类[场景]
classBoxScene      		= function(name, params)
	-- [参数赋值]
	params = totable(params)
	name = DISTINGUISHED_NAME_SCENE and name .. NAMING_SCENE or name
	-- [实例化]
	local o = class(name, bb.FBoxScene)
	o.name = name						-- 类名称
	o.TAG  = params.TAG or name			-- 类标签(用于日志记录等相关操作)

	return o
end

-- 跳转[场景]
function bb.GameBase:enterSceneWithBox(name, args)
	name = ifnil(name, "ui1")
    local scene = require("app.box." .. name .. ".scene." .. S.capitalize(name) .. "Scene").new(args)
    D.replaceScene(scene)
end







----------------------
-- 全局方法
----------------------
--===========
-- 状态控制
--===========
-- 判断是否发布到儿童版
function box.isPublishKids()
	return BB_PUBLISH_KIDS == TRUE_STRING
end

-- 判断是否已经发布
function box.isPublished()
	if isios() then 
		local marketId = G_APP_ID
        return S.isNotEmpty(marketId)
    end
    return true
end

-- 判断是否跳过盒子
function box.isSkipBus()
	-- print("box.isPublishKids() or ENABLED_EI_BOX_SKIP_BUS == true or G_BOX_SKIP_BOX or (not bb.UNet.isLocalWiFiAvailable())", box.isPublishKids() or ENABLED_EI_BOX_SKIP_BUS == true or G_BOX_SKIP_BOX or (not bb.UNet.isLocalWiFiAvailable()))
	-- print("box.isPublishKids()", box.isPublishKids())
	-- print(" ENABLED_EI_BOX_SKIP_BUS == true",  ENABLED_EI_BOX_SKIP_BUS == true)
	-- print("G_BOX_SKIP_BOX", G_BOX_SKIP_BOX)
	-- print(" (not bb.UNet.isLocalWiFiAvailable()" , (not bb.UNet.isLocalWiFiAvailable()))
	G_BOX_SKIP_BOX = true
	return box.isPublishKids() or ENABLED_EI_BOX_SKIP_BUS == true or G_BOX_SKIP_BOX or (not bb.UNet.isLocalWiFiAvailable())
end



-------------
-- 场景切换
-------------
function box.entryName()
	return "ui2"
end

-- 进入场景[游戏]
function box.enterGameScene(isAnimate)
	isAnimate = ifnil(isAnimate, true)

	if isAnimate then 
		game:enterScene(GAME_ENTRY_MODULE, nil, "fade", 1.0, COLOR3_WHITE)
	else
		game:enterScene(GAME_ENTRY_MODULE)
	end
end
-- 进入场景[盒子]
function box.enterBoxScene(isAnimate)
	isAnimate  = ifnil(isAnimate, true)
	local jump = box.entryName()

	if isAnimate then 
		game:enterSceneWithBox(jump, nil, "fade")
	else
		game:enterSceneWithBox(jump)
	end
end